<?php 
//Security Checking for the user if allowed to login.
session_start();
if(strlen($_SESSION['u_name'])==0)
{
	?>
	<script>
	window.open("admin-login.php","_self");
	</script>
	<?php 
	exit;
}

if($_SESSION['is_admin']=="N")
{
	?>
	<script>
	window.open("admin-homepage.php","_self");
	</script>
	<?php 
	exit;
}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.body {
	background-color:#a6bf79;
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	margin: 10px 10px 10px 10px;
	padding: 0px;
}
.textLike
{
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	padding: 0px;
}
</style>
<script type="text/javascript">

	function addNewCategory()
	{//---Adds New Category
		var categoryName = document.getElementById('txtAddCategory').value;
		if(categoryName.length>0)
		{
			$.post("category-functions.php",{name:categoryName,action:"add"},function(data){
				if(data==1)
				{
					alert("Category Successfully Edited.");
					window.location.reload();
				}
				else
				{
					alert("There was an error while editing the category. Please try later.");
					return false;
				}
			},"text");
		}
		else
		{
			alert("Category name can not be blank");
			return false;
		}
	}

	function addCategory()
	{//---Opens Add category Div
		document.getElementById('divAddCBTN').style.display="none";
		document.getElementById('divAddCategory').style.display="block";
	}

	function editCategory(id)
	{// Edit Category
		if(id.length>0)
		{
			var editId = "txtCategoryName_"+id;
			var offId = "spanCategoryName_"+id;
			document.getElementById(editId).style.display="block";
			document.getElementById(offId).style.display="none";
			document.getElementById('btnSaveCategory').style.display="block";
			document.getElementById('btnEditCategory').style.display="none";
		}
		else
		{
			alert("There was an error while editing the category. Please try later.");
			return false;
		}
	}
	function saveeditCategory(id)
	{ // Save Edited Category
		if(id.length>0)
		{
			var editId = "txtCategoryName_"+id;
			//alert(editId);
			//alert(document.getElementById(editId));
			var editedName = document.getElementById(editId).value;
			//alert(document.getElementById(editId).value);
			if(editedName.length==0)
			{
				alert("Category name can not be blank");
				return false;
			}
			else
			{
				$.post("category-functions.php",{id:id,name:editedName,action:"edit"},function(data){
					if(data==1)
					{
						alert("Category Successfully Edited.");
						window.location.reload();
					}
					else
					{
						alert("There was an error while editing the category. Please try later.");
						return false;
					}
				},"text");
			}
		}
		else
		{
			alert("There was an error while editing the category. Please try later.");
			return false;
		}
	}
	function deleteCategory(id)
	{ // Delete Category
		if(id.length>0)
		{
			$.post("category-functions.php",{id:id,action:"delete"},function(data){
				if(data==1)
				{
					alert("Category Successfully Deleted.");
					window.location.reload();
				}
				else
				{
					alert("There was an error while deleting the category. Please try later.");
					return false;
				}
			},"text");
		}
		else
		{
			alert("Please select one category.");
			return false;
		}
	}
	
</script>
<title>Admin -HomePage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="../js/jquery-1.4.2.js" type="text/javascript" language="javascript"></script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/menu.css" rel="stylesheet" type="text/css" />
</head>
<body class="body">
<div id="body" style="min-height:130px;height: auto;width:960px;">
<div align="center">
<!-- Admin Home Page Menu Bar -->

<ul id="list-nav">
<li><a href="admin-homepage.php">Home</a></li>
<li><a href="admin-homepage.php">All Listings</a></li>
<!--<li><a href="approved-listing.php">Approved Listing</a></li>-->
<li><a href="unapproved-listing.php">Deactivated Listing</a></li>
<li><a href="new-listing.php">New Lists</a></li>
<li><a href="admin-themelist.php">Theme List</a></li>
<li><a href="secure.php?logout=yes">Log Out</a></li>
</ul>



<!-- Menu Bar Ends -->
</div>
<br />

<?php 
/*
 * Summary : Created By Avik on 21th April,2010
 * Version : 1.0
 * Contents: This file Shows All the data Categories 
 * Changes
 */

#===========AUTHENTICATION========================#
session_start();
if(empty($_SESSION['u_name']))
{
	header("Location:admin-login.php");
}
//#########INCLUDE FILES########
include_once '../conf/db-config.php';
include_once '../conf/error.php';
include_once '../clsFetchData.php';
//##############################

$objFetchData = new clsFetchData();
$arrcategoryListing = array();

$arrcategoryListing  = $objFetchData->FetchAllCategories();
 
/*
 * SHOW ALL CATEGORIES
 */

if(is_array($arrcategoryListing) && count($arrcategoryListing)>0)
{
	?>
	<table cellpadding="0" cellspacing="10" border="0" width="820" style="padding-left: 50px;min-height:80px;height: auto;">
	<tr>
		<td height="20px" align="right" style="padding-right: 0px;">
			<a href="changepassword.php">Change Password</a>
		</td>
	</tr>
	<tr>
	<td>
		<div style="background:white;background-repeat: repeat-x;min-height:80px;width:820px;margin: 0 auto;height: auto;border-left:1px #35BAF5 solid;border-right:1px #35BAF5 solid;border-top:1px #35BAF5 solid;border-bottom:1px #35BAF5 solid;">
		<table cellpadding="0" cellspacing="4" width="800" >
		<tr>
			<td>&nbsp;</td>
		</tr>
		<?php 
		$icount=1;
		foreach ($arrcategoryListing as $arrData)
		{
			?>
			<tr>
				<td width="100" align="right" class="textLike">
					<?php echo $icount; ?>
				</td>
				<td width="10">&nbsp;</td>
				<td  width="400" align="center" class="textLike">
					<span class="textLike" id="spanCategoryName_<?php echo $arrData['sl_no']; ?>"><?php echo $arrData['name']; ?></span>
					<input class="textLike" type="text" name="txtCategoryName_<?php echo $arrData['sl_no']; ?>" id="txtCategoryName_<?php echo $arrData['sl_no']; ?>" value="<?php echo $arrData['name']; ?>" style="display: none"  />
				</td>
				<td width="100">
					<input style="cursor: pointer;" class="normalbtn" type="button" name="btnEditCategory" id="btnEditCategory" value="Edit >>" onclick="editCategory('<?php echo $arrData['sl_no']; ?>');" />
					<input style="cursor: pointer;display: none;" class="normalbtn" type="button" name="btnSaveCategory" id="btnSaveCategory" value="Save >>" onclick="saveeditCategory('<?php echo $arrData['sl_no']; ?>');"  />
				</td>
				<td width="100">
					<input style="cursor: pointer;" class="normalbtn" type="button" name="btnDeleteCategory" id="btnDeleteCategory" value="Delete >>" onclick="deleteCategory('<?php echo $arrData['sl_no']; ?>');" />
				</td>
			</tr>
			<?php 
			$icount++;
		}
			?>
		</table>
		</div>
		</td>
		</tr>
		</table>
	<?php 
}
else
{
	print "<br />No Data Found";
}

?>
<div id="divAddCBTN" style="height: 25px;">
<table cellpadding="0" cellspacing="10" border="0" width="870"  style="padding-left: 50px;min-height: 20px;height: auto;">
<tr>
	<td width="200" align="right">
		&nbsp;
	</td>
	<td width="270">&nbsp;</td>
	<td  width="400" align="right" style="padding-right: 25px;">
		<input type="button" id="btnAddCategory" name="btnAddCategory" value="Add Category >>" class="normalbtn" onclick="addCategory();" />
	</td>
</tr>
</table>
</div>

<!-- Add Category Div -->
<div id="divAddCategory" style="display: none;height: 30px;">
	<table cellpadding="0" cellspacing="10" border="0" width="870" style="padding-left: 50px;">
	<tr>
		<td width="200" align="right">
			<span>Add Category Name: </span>
		</td>
		<td width="270">&nbsp;</td>
		<td  width="400" align="right" style="padding-right: 25px;">
			<input type="text" id="txtAddCategory" name="txtAddCategory" size="20" />
		</td>
	</tr>
	<tr>
		<td width="200" align="right">
			&nbsp;
		</td>
		<td width="270">&nbsp;</td>
		<td  width="400" align="right" style="padding-right: 25px;">
			<input type="button" id="btnAddCategory" name="btnAddCategory" value="Add New Category" class="normalbtn" onclick="addNewCategory();" />
		</td>
	</tr>
	
	</table>
</div>
<!-- Add Category Div Ends -->
</div>



</body>
</html>